package com.example.feign;

import com.alibaba.fastjson.JSONObject;
import feign.Feign;
import feign.QueryMap;
import feign.Target;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.okhttp.OkHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Service;

import java.net.URI;
import java.util.Map;

@Service
@Import(FeignClientsConfiguration.class)
public class HttpDynaServiceImpl implements HttpDynaService {

    private HttpDynaConsumeService httpDynaConsumeService;

    @Autowired
    public HttpDynaServiceImpl(Decoder decoder, Encoder encoder) {
        httpDynaConsumeService = Feign.builder()
                .client(new OkHttpClient())
                .encoder(encoder)
                .decoder(decoder)
                .target(Target.EmptyTarget.create(HttpDynaConsumeService.class));
    }

    @Override
    public String getGoodsList(URI uri, Map<String, Object> map) {
        return httpDynaConsumeService.getGoodsList(uri,map);
    }

    @Override
    public String postGoodsList(URI uri, Map<String, Object> map) {
        return httpDynaConsumeService.postGoodsList(uri,map);
    }

    public String getGoodsList(URI uri){
        return httpDynaConsumeService.getGoodsList(uri);
    }

    @Override
    public String qryBalByDate(URI uri, JSONObject jsonObject) {
        return httpDynaConsumeService.qryBalByDate(uri,jsonObject);
//        return httpDynaConsumeService.getGoodsList(uri,jsonObject);
    }

    @Override
    public String qryBalByDate(URI uri, JSONObject jsonObject, Map<String, Object> map) {
        return httpDynaConsumeService.qryBalByDate(uri,jsonObject,map);
    }

    @Override
    public String postGoodsList(URI uri) {
        return httpDynaConsumeService.postGoodsList(uri);
    }

    @Override
    public String getGoodsList(URI uri, Map<String, Object> map, Map<String, Object> headmap) {
        return httpDynaConsumeService.getGoodsList(uri,map,headmap);
    }

    @Override
    public String qryBalByDate(URI uri, Map<String, Object> paramMap, JSONObject jsonObject, Map<String, Object> headMap) {
        return httpDynaConsumeService.qryBalByDate(uri,paramMap,jsonObject,headMap);
    }

    @Override
    public String headRequest(URI uri, Map<String, Object> headMap) {
        return httpDynaConsumeService.headRequest(uri,headMap);
    }

}
